
<!--- ==================================================
NAME:		input_createorder.cfm
DESC:		The XML for XTI needed to add a new order or
			quote.  This is called from
			act_createorder.cfm by way of
			xti_handler.cfm.
			
See xti_createorder.cfm for a listing of the parameters
used in this XML definition			
=================================================== --->

<cfparam name="attributes.url" default="#application.xtiurl#">
<cfparam name="attributes.dtd" default="#application.xtidtd#">
<cfparam name="attributes.debug" default="false">
<cfparam name="attributes.debuglevel" default="1,2,3">
<cfparam name="attributes.customerid">
<cfparam name="attributes.contactid" default="">
<cfparam name="attributes.crt_order" default="">
<cfparam name="attributes.returnvar" default="neworder">
<!--- ORDER HEADER --->
<cfparam name="attributes.misc_code_1" default="">
<cfparam name="attributes.misc_amt_1" default="">
<cfparam name="attributes.misc_code_2" default="">
<cfparam name="attributes.misc_amt_2" default="">
<cfparam name="attributes.source">
<cfparam name="attributes.ship_complete" default="">
<cfparam name="attributes.tsr_taker">
<cfparam name="attributes.user" default="web">
<cfparam name="attributes.client_order" default="">
<cfparam name="attributes.order_type" default="R">
<cfparam name="attributes.program_id" default="">
<cfparam name="attributes.locid" default="">
<cfparam name="attributes.cid" default="">
<cfparam name="attributes.confidence" default="">
<cfparam name="attributes.close_date" default="">
<cfparam name="attributes.close_amt" default="">
<cfparam name="attributes.ds_loc"  default=""><!---added for P2666---->
<cfparam name="attributes.currency" default="USD"> <!--- default to US Dollars if no value is provided --->

<!--- PAYMENT TYPE --->
<cfif attributes.payment_type is "v" or attributes.payment_type is "m" or attributes.payment_type is "d">
	<cfparam name="attributes.payment_type" default="Credit_Card">
<cfelse>
	<cfparam name="attributes.payment_type">
</cfif>
<cfparam name="attributes.card_number" default="">
<cfparam name="attributes.expr_date" default="">
<cfparam name="attributes.amex_num" default="">
<cfparam name="attributes.security_code" default="">
<cfparam name="po_num" default="">

<cfif po_num is not "">
	<cfparam name="attributes.po_number" default="#po_num#">
<cfelse>
	<cfparam name="attributes.po_number" default="">
</cfif>
<!--- SHIPPING PARAMS --->
<cfparam name="attributes.company_name">
<cfparam name="attributes.attention">
<cfparam name="attributes.address1">
<cfparam name="attributes.address2" default="">
<cfparam name="attributes.address3" default="">
<cfparam name="attributes.address4" default="">
<cfparam name="attributes.city">
<cfparam name="attributes.state">
<cfparam name="attributes.country">
<cfparam name="attributes.zip" default="">
<cfparam name="attributes.geo_code" default="">
<cfparam name="attributes.phone" default="">

<!---SHIPPING CODES  --->
<cfparam name="attributes.code">
<cfparam name="attributes.account_number" default="">
<cfparam name="attributes.ship_price">
<cfparam name="attributes.ship_code_reason" default="">
<!--- SYSTEM NOTES --->
<cfparam name="attributes.packing_slip_notes" default="">
<cfparam name="attributes.invoice_notes" default="">
<cfparam name="attributes.management_notes" default="">
<cfparam name="attributes.auto_bo" default="">
<cfparam name="attributes.future_ship" default="">
<!--- ARRAYS SYSTEM AND LINITEM  --->
<cfparam name="attributes.array_parts">
<cfparam name="attributes.array_systems" default="">


<!---<cfdump var="#attributes.array_systems#">
<cfdump var="#attributes.array_parts#"><cfabort>--->

<!--- Build the XML package for XTI --->
<cfscript>
cart = "";
subtotal = 0;
// Start with standalone parts
if  (isarray(attributes.array_parts) and arraylen(attributes.array_parts) GT 0) {
	indexcnt = arraylen(attributes.array_parts) + 1;
	for ( i=1; i lt indexcnt ; i=i+1) {
      cart = cart & '
         <line_item>
            <product>
               <product_code>#ucase(attributes.array_parts[i].product)#</product_code>
               <quantity>#ucase(attributes.array_parts[i].quantity)#</quantity>
               <price>#ucase(attributes.array_parts[i].price)#</price>
               <list_price>#ucase(attributes.array_parts[i].list_price)#</list_price>
               <floor_price>#ucase(attributes.array_parts[i].floor_price)#</floor_price>
			   <promo_code_1>#ucase(attributes.array_parts[i].promo_code_1)#</promo_code_1>
			   <promo_code_2>#ucase(attributes.array_parts[i].promo_code_2)#</promo_code_2>
               <rsn_code_prc>#ucase(attributes.array_parts[i].price_reason_code)#</rsn_code_prc>
               <bid>#ucase(attributes.array_parts[i].bid)#</bid>
               <bid_exp>#ucase(attributes.array_parts[i].bid_exp)#</bid_exp>';
			   if (IsDefined("application.license_subscription") AND application.license_subscription EQ '1'){
               cart = cart & '
               <reoccurrence>#Trim(attributes.array_parts[i].number_reoccurrences)#</reoccurrence>
               <start_date>#DateFormat(ucase(attributes.array_parts[i].subscription_start_date), 'MMDDYY')#</start_date>
               <ori_order>#Trim(attributes.array_parts[i].ori_order)#</ori_order>';
			   }
			   cart = cart & '
            </product>
         </line_item>
      ';
	}
}

// Now the systems /*#ucase(attributes.array_parts[i].promo_code_1)#*//*#ucase(attributes.array_parts[i].promo_code_2)#*/
if  (isarray(attributes.array_systems) and arraylen(attributes.array_systems)) {
	indexcnt1 = arraylen(attributes.array_systems) + 1;  
 //writeoutput(arraylen(attributes.array_systems));
	for (x=1; x lt indexcnt1; x=x+1) {
      cart = cart & '
         <line_item>
            <configuration>
               <quantity>#ucase(attributes.array_systems[x].quantity)#</quantity>
               <baseunit>
                  <product_code>#ucase(attributes.array_systems[x].b_product)#</product_code>
                  <price>#ucase(attributes.array_systems[x].b_price)#</price>
                  <list_price>#ucase(attributes.array_systems[x].b_list_price)#</list_price>
                  <floor_price>#ucase(attributes.array_systems[x].b_floor_price)#</floor_price>
				  <promo_code_1></promo_code_1>
			   	  <promo_code_2></promo_code_2>
                  <rsn_code_prc>#ucase(attributes.array_systems[x].price_reason_code)#</rsn_code_prc>
                  <bid>#ucase(attributes.array_systems[x].bid)#</bid>
                  <bid_exp>#ucase(attributes.array_systems[x].bid_exp)#</bid_exp>
				  <manufacturer_part>#attributes.array_systems[x].manufacturer_part#</manufacturer_part>
               </baseunit>';
		indexcnt2 = arraylen(attributes.array_systems[x].subitem) + 1; 					
	//writeoutput(arraylen(attributes.array_systems[x].subitem));
	for (y=1; y lt indexcnt2;  y=y+1) {
      cart = cart & '
               <component>
                  <product_code>#ucase(attributes.array_systems[x].subitem[y].product)#</product_code>
                  <quantity>#ucase(attributes.array_systems[x].subitem[y].quantity)#</quantity>
                  <price>#ucase(attributes.array_systems[x].subitem[y].price)#</price>
                  <rsn_code_prc>#ucase(attributes.array_systems[x].subitem[y].price_reason_code)#</rsn_code_prc>
               </component>';
		}
		cart = cart & ' 
            </configuration>
         </line_item>';
	}
}
// Now build the rest of the xml to post to middle ware. KEEP FORMATING SAME AS BELOW...
xml = '<!DOCTYPE copy SYSTEM "#attributes.dtd#">
<xtiinput>
   <inputheader>
      <actionset>
         <action>crt_order</action>
      </actionset>
   </inputheader>
   <inputdata>
      <customerid>#ucase(attributes.customerid)#</customerid>
      <contactid>#ucase(attributes.contactid)#</contactid>
      <order_header>
         <misc_code_1>#ucase(attributes.misc_code_1)#</misc_code_1>
         <misc_amt_1>#ucase(attributes.misc_amt_1)#</misc_amt_1>
         <misc_code_2>#ucase(attributes.misc_code_2)#</misc_code_2>
         <misc_amt_2>#ucase(attributes.misc_amt_2)#</misc_amt_2>
         <source>#ucase(attributes.source)#</source>
         <ship_complete>#ucase(attributes.ship_complete)#</ship_complete>
         <tsr_taker>#attributes.tsr_taker#</tsr_taker>
         <user>#ucase(attributes.user)#</user>
         <client_order>#ucase(attributes.client_order)#</client_order>
         <order_type>#xmlformat(ucase(attributes.order_type))#</order_type>
         <pay_type>#attributes.pay_type#</pay_type>
         <program_id>#attributes.program_id#</program_id>
         <locid>#attributes.locid#</locid>
         <cid>#attributes.cid#</cid>
         <confidence>#attributes.confidence#</confidence>
         <close_date>#attributes.close_date#</close_date>
         <close_amt>#attributes.close_amt#</close_amt>
         <future_ship_date>#ucase(attributes.future_ship)#</future_ship_date>
         <auto_bo>#ucase(attributes.auto_bo)#</auto_bo>
         <ds_loc>#ucase(attributes.ds_loc)#</ds_loc>
         <currency>#trim(attributes.currency)#</currency>
      </order_header>
      <payment type="#attributes.payment_type#">
         <card_number>#ucase(attributes.card_number)#</card_number>
         <expr_date>#ucase(attributes.expr_date)#</expr_date>
         <amex_num>#ucase(attributes.amex_num)#</amex_num>
         <po_number>#ucase(attributes.po_number)#</po_number>
         <security_code>#ucase(attributes.security_code)#</security_code>
      </payment>
      <shipping_addr>
         <company_name>#xmlformat(ucase(attributes.company_name))#</company_name>
         <attention>#xmlformat(ucase(attributes.attention))#</attention>
         <address_1>#xmlformat(ucase(attributes.address1))#</address_1>
         <address_2>#xmlformat(ucase(attributes.address2))#</address_2>
         <city>#ucase(attributes.city)#</city>
         <state>#ucase(attributes.state)#</state>
         <country>#ucase(attributes.country)#</country>
         <zip>#ucase(attributes.zip)#</zip>
         <geo_code>#ucase(attributes.geo_code)#</geo_code>
         <phone>#ucase(attributes.phone)#</phone>
      </shipping_addr>
      <shipping_codes>
         <method>
            <code>#ucase(attributes.code)#</code>
            <account_number>#ucase(attributes.account_number)#</account_number>
            <price>#ucase(attributes.ship_price)#</price>
            <rsn_code_ship>#ucase(attributes.ship_code_reason)#</rsn_code_ship>
            <ship_chg_reason>#ucase(attributes.ship_code_reason)#</ship_chg_reason>
         </method>
      </shipping_codes>
      <system_notes>
         <packing_slip_notes>#ucase(attributes.packing_slip_notes)#</packing_slip_notes>
         <invoice_notes>#ucase(attributes.invoice_notes)#</invoice_notes>
         <management_notes>#ucase(attributes.management_notes)#</management_notes>
      </system_notes>
      <shopping_cart>
         #cart#
      </shopping_cart>
   </inputdata>
</xtiinput>';
//<rsn_code_ship>#ucase(attributes.ship_code_reason)#</rsn_code_ship>
</cfscript>